В Python блок else может располагаться не только после if, но и после for и while. Код внутри else выполняется, если цикл не был прерван оператором break.
Обычный способ использования этого — найти что-то в цикле и выйти из него через break, когда нужный элемент найден:
>>> first_odd = None >>> for x in [2, 3, 4, 5]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... >>> first_odd 3
>>> for x in [2, 4, 6]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... ... ValueError: В списке нет нечетных элементов
В Python блок else может располагаться не только после if, но и после for и while. Код внутри else выполняется, если цикл не был прерван оператором break.
Обычный способ использования этого — найти что-то в цикле и выйти из него через break, когда нужный элемент найден:
>>> first_odd = None >>> for x in [2, 3, 4, 5]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... >>> first_odd 3
>>> for x in [2, 4, 6]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... ... ValueError: В списке нет нечетных элементов
Telegram has exploded as a hub for cybercriminals looking to buy, sell and share stolen data and hacking tools, new research shows, as the messaging app emerges as an alternative to the dark web.An investigation by cyber intelligence group Cyberint, together with the Financial Times, found a ballooning network of hackers sharing data leaks on the popular messaging platform, sometimes in channels with tens of thousands of subscribers, lured by its ease of use and light-touch moderation.
How Does Bitcoin Mining Work?
Bitcoin mining is the process of adding new transactions to the Bitcoin blockchain. It’s a tough job. People who choose to mine Bitcoin use a process called proof of work, deploying computers in a race to solve mathematical puzzles that verify transactions.To entice miners to keep racing to solve the puzzles and support the overall system, the Bitcoin code rewards miners with new Bitcoins. “This is how new coins are created” and new transactions are added to the blockchain, says Okoro.